Vector = {
	x = 0, y = 0, z = 0,
	magnitude,
	New = function( self, o )
		local o = o or {}	
		setmetatable( o, self )
		self.__index = self
		self.__add = self.Add
		self.__sub = self.Sub
		self.__unm = self.Negative
		o.magnitude = o:Magnitude()
		return o
	end,
	SetVector = function( self, v )
		self.x = v.x
		self.y = v.y
		self.z = v.z
	end,
	Magnitude = function( self )
		magnitude = math.sqrt( self.x * self.x + self.y * self.y + self.z * self.z )
		return magnitude
	end,
	Normalize = function( self )
		self:Magnitude()
		local invMag = 1.0 / self.magnitude
		self.x = invMag * self.x
		self.y = invMag * self.y
		self.z = invMag * self.z
	end,
	Dot = function( self, v )
		ret = self.x * v.x + self.y * v.y + self.z * v.z;	
		return ret
	end,
	Cross = function( self, v )
		ret = {}
		ret.x =  ( self.y * v.z - self.z * v.y )
		ret.y = -( self.x * v.z - self.z * v.x )
		ret.z =  ( self.x * v.y - self.y * v.x )
		return Vector:New( ret )
	end,
	Add = function ( self, v )
		ret = {} 	
		ret.x = ( self.x + v.x )
		ret.y = ( self.y + v.y )
		ret.z = ( self.z + v.z )
		return Vector:New( ret )
	end,
	Sub = function ( self, v )
		ret = {}
		ret.x = ( self.x - v.x )
		ret.y = ( self.y - v.y )
		ret.z = ( self.z - v.z )
		return Vector:New( ret )
	end,
	Negative = function ( self )
		ret = { }
		ret.x = -self.x
		ret.y = -self.y
		ret.z = -self.z
		return Vector:New( ret ) 
	end,
}

